package post;

import java.util.List;

import javax.jdo.JDOObjectNotFoundException;
import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import yxnote.PMF;

public class Utils {
   
    public static List<Post> find() {
        PersistenceManager pm = PMF.get().getPersistenceManager();
        Query query = pm.newQuery(Post.class);
        List<Post> posts = (List<Post>) query.execute();
        return posts;
    }
    
    public static Post find(String id) {
        PersistenceManager pm = PMF.get().getPersistenceManager();
        
        try {
            Post p = pm.getObjectById(Post.class, Long.valueOf(id));
            return p;
        } catch (JDOObjectNotFoundException e) {
            return null;
        } finally {
            pm.close();
        }
    }
}
